import 'package:app/common/app_theme.dart';
import 'package:app/common/colors.dart';
import 'package:app/common/tool.dart';
import 'package:app/components/base_scaffold_appbar.dart';
import 'package:app/components/my_webview.dart';
import 'package:app/pages/reward_modules/RewardModel.dart';
import 'package:app/pages/reward_modules/reward_detail_module/reward_detail_model.dart';
import 'package:app/services/address.dart';
import 'package:app/services/dio_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';

class RewardDetailPage extends StatefulWidget {

  var id;

  RewardDetailPage(this.id,{Key? key}) : super(key: key);

  @override
  State<RewardDetailPage> createState() => _RewardDetailPageState();
}

class _RewardDetailPageState extends State<RewardDetailPage> {




  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    requestData();
  }

  RewardDetailModel? model;

  requestData()async{

    var json = await DioManager().kkRequest('${Address.rewardDetail}/${widget.id}',method: 'get');

    RewardDetailModel rewardDetailModel = RewardDetailModel.fromJson(json);

    model = rewardDetailModel;

    setState(() {

    });


  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.bgColor,
      appBar: BaseAppBar(
        preferredSize: Size(Get.width,AppTool.appBarHEIGHT),
        child: Text('详情'),
      ),
      body: ListView(
        padding: EdgeInsets.only(left: 0,top: 15),
        children: [
          Container(
            padding: EdgeInsets.only(left: 15,right: 15),
            color: Colors.white,
            alignment: Alignment.centerLeft,
            height: 40,
            child:  Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text('类型',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                Text('${model?.data?.typeName??''}'),
              ],
            )
          ),
          SizedBox(height: 1,),
          Container(
              padding: EdgeInsets.only(left: 15,right: 15),
              color: Colors.white,
              alignment: Alignment.centerLeft,
              height: 40,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('状态:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                  Text('${model?.data?.status??''}'),
                ],
              )
          ),
          SizedBox(height: 1,),
          Container(
              padding: EdgeInsets.only(left: 15,right: 15),
              color: Colors.white,
              alignment: Alignment.centerLeft,
              height: 40,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('项目:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                  Text('${model?.data?.cases??''}'),
                ],
              )
          ),
          SizedBox(height: 1,),
          Container(
              padding: EdgeInsets.only(left: 15,right: 15),
              color: Colors.white,
              alignment: Alignment.centerLeft,
              height: 40,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('金钱:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                  Text('${model?.data?.money??'0'}元'),
                ],
              )
          ),
          Container(
              padding: EdgeInsets.only(left: 15,right: 15),
              color: Colors.white,
              alignment: Alignment.centerLeft,
              height: 40,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('物品:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                  Text('${model?.data?.thing??''}'),
                ],
              )
          ),
          Container(
              padding: EdgeInsets.only(left: 15,right: 15),
              color: Colors.white,
              alignment: Alignment.centerLeft,
              height: 40,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text('日期:',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                  Text('${model?.data?.date??''}'),
                ],
              )
          ),
          SizedBox(height: 15,),
          Container(
            height: 80,
            color: Colors.white,
            padding: EdgeInsets.only(top: 10,left: 15),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text('附件',style: appThemeData.textTheme.subtitle1!.copyWith(fontSize: 15),),
                Container(
                  width: Get.width,
                  color: Colors.white,
                  child: GestureDetector(
                    onTap: (){
                      Get.to(MyWebView('title', '${model?.data?.attachment?.previewUrl}'));
                    },
                    child:Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            SvgPicture.network('${Address.homeHost}${model?.data?.attachment?.icon}',
                              width: 22,height: 22,),
                            Text('${model?.data?.attachment?.name}'),
                          ],
                        ),
                        IconButton(onPressed: (){
                          launch(model!.data!.attachment!.url!);
                        }, icon: Image.asset('images/down_icon.png',width: 24,height: 24,))
                        // TextButton(onPressed: ()async{
                        //   launch(model!.data!.attachment!.url!);
                        //
                        //   // Get.to(MyWebView('', model?.data?.attachment?.url));
                        // }, child: Text('下载')),
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
        ],
      ),
    );
  }
}
